package io.renren.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import io.renren.common.exception.RRException;
import io.renren.common.utils.RedisUtils;
import io.renren.config.RabbitConfig;
import io.renren.utils.IdWorker;
import io.renren.utils.RabbitUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component("rebaseTask")
public class RebaseTask implements ITask {
    @Autowired
    private RabbitUtils rabbitUtils;

    @Override
    public void run(String params) {
        // 返佣冻结表资金转入会员账户
        if (StringUtils.isBlank(params)) {
            throw new RRException("参数不能为空");
        }
        Map<String, Object> map = JSON.parseObject(params, new TypeReference<Map<String, Object>>() {
        });
        Integer orderId = (Integer) map.get("orderId");
        if (orderId == null) {
            throw new RRException("订单id不能为空");
        }

        rabbitUtils.sendMsg(RabbitConfig.EXCHANGE_DIRECT_FREEZE, RabbitConfig.ROUTINGKEY_FREEZE, map);
    }
}
